home *** CD-ROM | disk | FTP | other *** search
/ HyperLib 1997 Winter - Disc 1 / HYPERLIB-1997-Winter-CD1.ISO.7z / HYPERLIB-1997-Winter-CD1.ISO / オンラインウェア / UTIL / Alpha 6.5.sit / Tcl / UserCode / Text Filters / Text Munging / wordcount < prev    next >
Text File  |  1993-10-19  |  665b  |  23 lines

  1. #!/usr/bin/perl
  2.  
  3. $/ = "";                        # Enable paragraph mode.
  4. $* = 1;                         # Enable multi-line patterns.
  5.  
  6. # Now read each paragraph and split into words.  Record each
  7. # instance of a word in the %wordcount associative array.
  8.  
  9. while (<>) {
  10.     s/-¥n//g;                   # Dehyphenate hyphenations.
  11.     tr/A-Z/a-z/;                # Canonicalize to lower case.
  12.     @words = split(/¥W*¥s+¥W*/, $_);
  13.     foreach $word (@words) {
  14.     $wordcount{$word}++;    # Increment the entry.
  15.     }
  16. }
  17.  
  18. # Now print out all the entries in the %wordcount array.
  19.  
  20. foreach $word (sort keys(%wordcount)) {
  21.     printf "%20s %d¥n", $word, $wordcount{$word};
  22. }
  23.